<?php
/*
根据配置生成编辑页面的各个输入字段
*/
	if (!$fields) $fields = array();
	foreach($fields as $name=>$data)
	{
		if (preg_match('/^__/',$name)) continue;
		if (!$data['type']) $data['type'] = 'text';
		echo "<tr><td>$data[name]";
		if (!$data['null']) echo '<span style="color:red">*</span>';
		echo "</td>";
		echo '<td>';
		
		$data['style'] .= ($data['width'])?'width:'.$data['width'].'px;':'';
		$data['style'] .= ($data['height'])?'height:'.$data['height'].'px;':'';
		
		$data['field_name'] = $name;
		$data['__orig_content'] = $content[$name];
		$data['content'] = $content[$name];
		
		if (!$data['content'] && $data['content'] !== 0 && $data['default']) $data['content'] = $data['default'];
		
		//显示之前的预处理
		if ($data['prefilter'] && function_exists($data['prefilter']))
		{
			$data['content'] = $data['prefilter']($data['content']);
		}
	
		if (function_exists($_func = 'endcms_input_'.$data['type']))
		{
			$_func($data); 
			//这些函数在helper/html.php里面
		}
		echo "</td></tr>\n";
	}
?>

<script>
$(function()
{
	var remove_row;
	$('span.del-row-bt').click(remove_row = function()
	{
		$(this).parents('div.list-row-wrapper').remove();
	});
	$('span.add-row-bt').click(function()
	{
		var div = $(this).parents('div.list-row-wrapper');
		var remove = div.find('.add-row-bt').attr('remove');
		var cloned = div.clone();
		cloned.insertAfter(div)
			.find('.add-row-bt')
			.removeClass('add-row-bt')
			.addClass('del-row-bt')
			.html(remove)
			.click(remove_row);
		cloned.find('input').val('');
	});
});
</script>